﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="房产销冠, 房地产,卡考网络" />
    <meta name="description" content="上海卡考网络有限公司" />
    <title>房产销冠</title>
    <link rel="stylesheet" href="css/list.css" type="text/css" />
    <link rel="stylesheet" href="css/global.css" type="text/css" />
    <link href="bootstrap/iCheck-master/skins/minimal/Orange.css" rel="stylesheet" type="text/css" />
    <!--<script src="js/jquery-1.8.3.min.js"></script>-->
    <!--<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />-->
    <script src="http://dn-blqw.qbox.me/jq+bs+art.js" type="text/javascript"></script>
    <!--<script src="js/jquery.easydropdown.min.js"></script>-->
    <script src="bootstrap/iCheck-master/icheck.js"></script>
    <!--<script src="bootstrap/js/bootstrap.min.js"></script>-->
    <!--<script src="js/checkbox.js"></script>-->
    <script src="js/common.js"></script>
    <script src="js/PageIndex.js"></script>
    <script src="http://dn-blqw.qbox.me/kk.js"></script>
    <script src="js/WdatePicker.js"></script>
    <!--<script src="http://static.tops001.com/openSource/iDialog/1.1/jquery.iDialog.js" dialog-theme="default"></script>-->
    <script src="Scripts/jquery.iDialog.js" dialog-theme="default"></script>
    <style>
        .from-control {
            width: 350px;
            margin: 10px 20px;
        }

        .page {
            margin: 15px 20px 15px 0;
            height: 30px;
        }

            .page li {
                min-width: 30px;
                height: 30px;
                line-height: 30px;
                margin-right: 10px;
                border-radius: 3px;
            }

                .page li.page_ic {
                    width: 120px;
                    color: #666666;
                    border: 0 none;
                }

                    .page li.page_ic:hover {
                        color: #666666;
                    }

        .page_ic input {
            width: 44px;
            height: 30px;
            line-height: 30px;
            border: 1px solid #e6e6e6;
            text-align: center;
            border-radius: 3px;
        }

        .page li.page_last {
            cursor: pointer;
            border-color: #0074d9;
            background: #0074d9;
            color: #fff;
            width: 40px;
        }

        .page_num {
            float: left;
            margin: 15px 0 15px 20px;
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #666666;
        }

            .page_num select {
                border: 1px solid #e6e6e6;
                border-radius: 3px;
            }
    </style>
</head>
<body style="background: #f1f1f1;">
    <div class="main01">
        <div class="content clearfix">
            <div class="headline02">
                <div class="line_left">兑换记录<span>(<b id="RecordCount">0</b>)</span></div>
                <div class="line_right">
                    <ul class="nav_line_right">
                        <li class="con"><a href="#">首页</a></li>
                        <li>/</li>
                        <li class="con"><a href="#">订单管理</a></li>
                        <li>/</li>
                        <li class="con"><a href="#" style="color: #60b12a;">兑换记录</a></li>
                    </ul>
                </div>
            </div>
            <div class="bton">
                <div class="bton_left">
                    <select id="F_CityKid" class="selall sel100 fl" style="margin-right:11px;margin-top:5px;margin-left:11px;">
                        <option value="-1">请选择</option>
                    </select>
                    <select id="F_Status" class="selall sel100 fl" style="margin-right:11px;margin-top:5px">
                        <option value="-1">订单状态</option>
                        <option value="1">待审核</option>
                        <option value="4">审核未通过</option>
                        <option value="9">审核已通过</option>
                        <option value="10">已发放</option>
                        <option value="2">兑换处理中</option>
                        <option value="3">兑换成功</option>
                    </select>
                    <select id="F_CateogryKid" class="selall sel100 fl" style="margin-right: 11px;margin-top:5px">
                        <option value="-1">商品类型</option>
                    </select>
                    <select id="F_ExchangeType" class="selall sel100 fl" style="margin-right: 11px;margin-top:5px">
                        <option value="-1">兑换类型</option>
                        <option value="1">5折秒杀</option>
                        <option value="2">大转盘活动</option>
                        <option value="3">正常兑换</option>
                    </select>
                </div>

                <div class="bton_right" style="margin-top:5px;">
                    <div class="bton_left_nav">
                        <a href="" class="btn_select" id="selboxbt">筛选</a>   
                        <a href="#" class="btn_craise" style="border:1px solid #e3e4e6;" onclick="f_AuditKids()">审核</a>
                        <a href="#" class="btn_deal" onclick="f_SendKids()" style="border:1px solid #e3e4e6;">发放</a>                        
                        <a href="#" class="btn_export" onclick="f_ExportExcel()" style="border:1px solid #e3e4e6;">导出</a>
                        <a href="" id="DownLoad" target="_blank" class="btn_export" style="display:none">下载</a>                          
                        <a href="javascript:document.location.reload();" class="btn_refresh" id="refresh">刷新</a>                   
                    </div>
                    <div class="bton_left_nav pageIn2">                        
                    </div>
                </div>
            </div>
        </div>


        <div style="min-height: 500px;">
            <table class="table03 tab_warp" style="width: 100%; max-height: 400px; table-layout: fixed; border-bottom: 1px #e6e6e6 solid;">
                <thead>
                    <tr class="info_title">
                        <th style="width:60px;">
                            <input type="checkbox" name="checkbox" id="checkAll" style="display:none" />
                        </th>
                        <th style="width: 60px" class="mid_line">序号</th>
                        <th style="width: 120px" class="mid_line">订单时间</th>
                        <th style="width: 120px;" class="mid_line">商品名称</th>
                        <th style="width: 70px;" class="mid_line">商品分类</th>
                        <th style="width: 120px" class="mid_line">订单号</th>
                        <th style="width: 100px;" class="mid_line">订单状态</th>
                        <th style="width: 70px;" class="mid_line">消耗积分</th>
                        <th style="width: 100px;" class="mid_line">用户名</th>
                        <th style="width: 50px;" class="mid_line">城市</th>
                        <th style="width: 100px;" class="mid_line">联系电话</th>
                        <th style="width: 200px;" class="mid_line">基本信息</th>
                        <th style="width: 200px"></th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="info_cont" style="display:none">
                        <td>
                            <input type="checkbox" name="subBox" value="{Kid}" status="{IsStatus_check}" class="subBox" />
                        </td>
                        <td>{F_Index}</td>
                        <td>{F_ExchangeTime}</td>
                        <td>{F_ProductName}</td>
                        <td>{F_CategoryName} </td>
                        <td>{F_OrderNo}</td>
                        <td>{F_IsStatus}</td>
                        <td>{F_PointNum}</td>
                        <td>{F_Title}</td>
                        <td>{F_Name}</td>
                        <td>{F_Phone}</td>
                        <td>{F_Consignee} {F_Mobile} {F_CompanyName} {F_CompanyAddress}</td>
                        <td>
                            <div class="reset">
                                {IsStatus}
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
            <!--放置分页 begin -->
            <table style="width: 100%; height: auto">
                <tr>
                    <td colspan="15">
                        <div class="pageIn"></div>
                    </td>
                </tr>
            </table>
            <!--放置分页 end -->
        </div>
    </div>
    <div id="selbox" class="clearfix" style="display:none">
        <div class="clearfix">
            <input type="text" class="selall sel100 fl from-control" id="orderNO" placeholder="订单号" onkeyup="clearNoPhone_Number(this)" max="25" onkeypress="    if (event.which == 13) { clearNoPhone_Number($('#orderno').val()); this.blur(); }" />
            <input type="text" class="selall sel100 fl from-control" id="productName" placeholder="商品名称" max="20" />
            <input type="text" class="selall sel100 fl from-control" id="brokerName" placeholder="经纪人姓名" max="10" />
            <input type="text" class="selall sel100 fl from-control" id="brokerPhone" placeholder="经纪人电话" onkeyup="clearNoPhone_Number(this)" maxlength="11" onkeypress="    if (event.which == 13) { clearNoPhone_Number($('#brokerPhone').val()); this.blur(); }" />
            <input type="text" class="selall sel100 fl from-control" id="lowPoint" placeholder="消耗最低积分" onkeyup="clearNoPhone_Number(this)" onkeypress="    if (event.which == 13) { clearNoPhone_Number($('#lowPoint').val()); this.blur(); }" />
            <input type="text" class="selall sel100 fl from-control" id="topPoint" placeholder="消耗最高积分" onkeyup="clearNoPhone_Number(this)" onkeypress="    if (event.which == 13) { clearNoPhone_Number($('#topPoint').val()); this.blur(); }" />
            <input type="text" class="selall sel100 fl from-control" id="agentStores" placeholder="经纪人门店" />
            <input type="text" class="selall sel100 fl from-control" id="expandingHeader" placeholder="拓展负责人" />
        </div>

        <div class="datatime">
            <input type="text" id="beginTime" name="beginTime" value="" onclick="WdatePicker()" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd'})" placeholder="  请选择开始时间"
                   style="line-height:28px;border:1px solid #e3e4e6;" class="from-control" />
            <input type="text" id="endTime" name="endTime" value="" onclick="WdatePicker()" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(\'beginTime\')}' })" placeholder="  请选择结束时间"
                   style="line-height:28px;border:1px solid #e3e4e6;margin-left:15px;" class="from-control" />
        </div>

        <div class=""></div>
    </div>
    <script src="js/list.js"></script>
    <script src="js/Page_New.js"></script>
    <script type="text/javascript">
        $(function () {
            f_GetProductCategoryList();
            f_GetData();
            //f_GetProductexchangeState();
            f_GetCityList();
            ChangeRefresh();
            countwidth();
        });

        $("#selboxbt").click(function () {
            showWindows("高级搜索", "selbox", f_Search, 800, 400);
            return false;
        })

        function showWindows(title, id, func, wt, h) {
            $.dialog({
                height: h,
                width: wt,
                fixed: true,
                lock: true,
                title: title,
                content: document.getElementById(id),
                btn: {                      //可以任意定义按钮个数
                    ok: {                     //按钮的key值，下次可用个btn方法从新设置
                        val: '确定',  //按钮显示的文本
                        type: 'orange',
                        click: function () {
                            func();
                        }
                    },
                    canle: {                     //按钮的key值，下次可用个btn方法从新设置
                        val: '取消',
                    }
                },
                init: function () {

                },
            });

        }

        function countwidth() {
            if (!$(".tab_warp").length) { return }
            var widthall = 0;
            var thall = $(".tab_warp th");
            for (var i = 0; i < thall.length; i++) {
                widthall = widthall + thall.eq(i).width();
            }
            if (widthall <= $("body").width() - 60) { widthall = $("body").width() - 60 }
            $(".main01").width(widthall);
        }

        function f_GetCityList() {
            var data = kk.api.get("/System/GetCityList", function (data) {
                $("#F_CityKid").empty();
                $.each(data, function (i, obj) {
                    $("#F_CityKid").append("<option value='" + obj.F_CityKid + "'>" + obj.F_CityName + "</option>");
                });
            });

        }

        //获取订单状态
        function f_GetProductexchangeState() {
            var data = kk.api.get("/ProductsExchange/GetExchangeState", function (data) {
                $.each(data, function (i, obj) {
                    $("#F_Status").append("<option value='" + obj.key + "'>" + obj.value + "</option>");
                });
            });

        }
        //获取商品类型
        function f_GetProductCategoryList() {
            $kk.api.get("/ProductsCategory/GetList", function (data) {
                $.each(data, function (i, obj) {
                    $("#F_CateogryKid").append("<option value='" + obj.Kid + "'>" + obj.F_CategoryName + "</option>");
                });
            });
        }


        var PageIndex = 1;
        function f_Search() {
            pageIndex = 1;
            f_GetData(pageIndex);
        }

        function f_UrlParStr() {
            var exchangeType = $("#F_ExchangeType option:selected").val();
            var categoryKid = $("#F_CateogryKid option:selected").val();
            var status = $("#F_Status option:selected").val();
            var orderNO = $("#orderNO").val();
            var productName = $("#productName").val();
            var brokerName = $("#brokerName").val();
            var brokerPhone = $("#brokerPhone").val();
            var lowPoint = $("#lowPoint").val();
            var topPoint = $("#topPoint").val();
            var cityKid = $("#F_CityKid option:selected").val();
            if (cityKid == undefined) {
                cityKid = -1;
            }
            var sdt = $("#beginTime").val();
            var edt = $("#endTime").val();
            var agentStores = $("#agentStores").val();
            var expandingHeader = $("#expandingHeader").val();
            return "?exchangeType=" + exchangeType + "&categoryKid=" + categoryKid + "&status=" + status + "&sdt=" +
                sdt + "&edt=" + edt + "&orderNO=" + orderNO + "&productName=" + productName + "&brokerName=" + brokerName + "&brokerPhone=" +
                brokerPhone + "&lowPoint=" + lowPoint + "&topPoint=" + topPoint + "&cityKid=" + cityKid + "&agentStores=" + agentStores + "&expandingHeader=" + expandingHeader + "&r=" + Math.random();
        }

        //获取记录信息
        function f_GetData(pageIndex) {
            var pageSize = $("#selectedPageSize").val();
            var idx = 0;
            var newUrlParStr = f_UrlParStr();
            $kk.api.get("/ProductsExchange/GetList" + newUrlParStr, { pageSize: pageSize, pageIndex: pageIndex }, function (res) {
                kk.fillTable(".table03", res.Items, function (data, name) {
                    if (name == "F_Index") {
                        idx++;
                        var otherCount = pageSize * (pageIndex - 1);
                        if (isNaN(otherCount)) {
                            otherCount = 0;
                        }
                        return idx + otherCount;
                    }
                    if (name == "F_IsStatus") {
                        switch (data[name]) {
                            case 1: return "审核中";
                            case 2: return "兑换处理中"
                            case 3: return "兑换成功";
                            case 4: return "审核不通过";
                            case 5: return "已使用";
                            case 6: return "失效";
                            case 7: return "已过期";
                            case 8: return "已撤销";
                            case 9: return "审核通过";
                            case 10: return "已发放";
                        }
                    }
                    if (name === "F_Title") {
                        if ($.trim(data[name]).length <= 0) {
                            return data["F_WX_Nickname"];
                        }
                    }
                    if (name == "IsStatus") {
                        switch (data["F_IsStatus"]) { //<a href="javascript:;" onclick="" class="btn_revise">编辑</a>
                            case 1:
                                return "<a href=\"javascript:;\" onclick=\"f_Audit(" + data["Kid"] + ",4)\" class=\"btn_revise\">审核不通过</a>"
                                    + "<a href=\"javascript:;\" onclick=\"f_Audit(" + data["Kid"] + ",9)\" class=\"btn_revise\">审核通过</a>";
                            case 2:
                                return "<a href=\"javascript:;\" onclick=\"f_Canceal(" + data["Kid"] + ")\" class=\"btn_revise\">撤销</a>";
                            case 3:
                            case 4: //return "<a href=\"javascript:;\" onclick=\"f_edit(" + data["Kid"] + ")\" class=\"btn_revise\">编辑</a>"
                            case 5:
                            case 6:
                            case 7:
                            case 8:
                            case 10: return "";
                            case 9: return "<a href=\"javascript:;\" onclick=\"f_Send(" + data["Kid"] + ",'" + data["F_Title"] + "','" + data["F_ExchangeTime"] + "','" + data["F_ProductName"] + "','" + data["F_Phone"] + "')\" class=\"btn_revise\">发放</a>";
                                //"<a href=\"javascript:;\" onclick=\"f_edit(" + data["Kid"] + ")\" class=\"btn_revise\">编辑</a>";
                        }
                    }
                    if (name == "IsStatus_check") {
                        return data["F_IsStatus"];
                    }

                });
                $("#RecordCount").html(res.Count);
                makePageBar(f_GetData, res.Count, pageIndex, pageSize);
                PageIndex = pageIndex;
                $(':checkbox').not(".notneeddraw").iCheck({
                    checkboxClass: 'icheckbox_minimal-orange',
                    radioClass: 'iradio_minimal-orange',
                    increaseArea: '20%' // optional
                });
                $('#checkAll').css('display', 'block');
                $('.info_title .iCheck-helper').on('click', function () {
                    if ($(".icheckbox_minimal-orange:first").hasClass("checked")) {
                        $('.subBox').iCheck('check');
                    } else {
                        $('.subBox').iCheck('uncheck');
                    }
                });
                $('.pageIn').on('click', function () {
                    //console.log(111);
                    $('.checked:first').iCheck('uncheck');
                })
            });
        }

        //撤销
        function f_Canceal(kid) {
            kk.confirm("确定撤销吗？", "提示", "", "", function () {
                kk.api.get("/ProductsExchange/Revoke", { kid: kid }, function (res) {
                    if (res) {
                        f_GetData(PageIndex);
                        $kk.popup("操作成功", "success", 1000);
                    } else {
                        $kk.popup("撤销成功", "danger", 1000);
                    }
                });
            });
        }

        //发放
        function f_Send(kid, customerName, orderTime, productName, phone) {
            var data = {
                kid: kid,
                customerName: customerName,
                orderTime: orderTime,
                productName: productName,
                phone: phone
            };
            kk.confirm("确定发放吗？", "提示", "", "", function () {
                kk.api.get("/ProductsExchange/Send", data, function (res) {
                    if (res) {
                        f_GetData(PageIndex);
                        $kk.popup("操作成功", "success", 1000);

                    } else {
                        $kk.popup("操作失败", "danger", 1000);

                    }
                });
            });
        }

        function f_SendKids() {
            var checkedKids = $('.subBox:checked');
            if (checkedKids.length < 1) {
                $kk.popup("至少需要选中一条记录", "danger", 3000);
            } else {
                var kids = '';
                checkedKids.each(function () {
                    if ($(this).attr('status') == 9) {
                        kids += ',' + $(this).val();
                    }
                });
                kids = kids.substr(1, kids.length - 1);
                kk.confirm(
                "确认所选兑换记录发放吗？"
                , "提示", "", "", function () {
                    kk.api.get("/ProductsExchange/SendKids", { kids: kids }, function (res) {
                        if (res) {
                            $kk.popup("操作成功", "success", 1000);
                            f_GetData(PageIndex);
                        } else {
                            $kk.popup("操作失败", "danger", 1000);
                        }
                    });
                }, null);
            }
        }

        //审核
        function f_Audit(kid, status) {
            kk.confirm("确定审核吗？", "提示", "", "", function () {
                kk.api.get("/ProductsExchange/Audit", { kid: kid, status: status }, function (res) {
                    if (res) {
                        $kk.popup("操作成功", "success", 1000);
                        f_GetData(PageIndex);
                    } else {
                        $kk.popup("操作失败", "danger", 1000);
                    }
                });
            }, null);
        }

        //批量审核
        function f_AuditKids() {
            var checkedKids = $('.subBox:checked');
            if (checkedKids.length < 1) {
                $kk.popup("至少需要选中一条记录", "danger", 3000);
            } else {
                var kids = '';
                checkedKids.each(function () {
                    if ($(this).attr('status') == 1) {
                        kids += ',' + $(this).val();
                    }
                });
                kids = kids.substr(1, kids.length - 1);
                //alert(kids);

                kk.confirm(
                "<label><input type='radio' value='9'name='edit' class='statusEdit' checked='checked'/>审核通过</label><br/>" +
                "<label><input type='radio' value='4'name='edit' class='statusEdit'/>审核不通过</label><br/>"
                , "提示", "", "", function () {
                    var status = $('.statusEdit:checked').val();
                    kk.api.get("/ProductsExchange/AuditKids", { kids: kids, status: status }, function (res) {
                        if (res) {
                            $kk.popup("操作成功", "success", 1000);
                            f_GetData(PageIndex);
                        } else {
                            $kk.popup("操作失败", "danger", 1000);
                        }
                    });
                }, null);
            }
        }

        //编辑
        function f_edit(kid) {
            kk.confirm(
                "<label><input type='radio' value='9'name='edit' class='statusEdit' checked='checked'/>审核通过</label><br/>" +
                "<label><input type='radio' value='4'name='edit' class='statusEdit'/>审核不通过</label><br/>"
                , "编辑", "", "", function () {
                    var status = $('.statusEdit:checked').val();
                    kk.api.get("/ProductsExchange/Edit", { kids: kid, status: status }, function (res) {
                        if (res) {
                            $kk.popup("操作成功", "success", 1000);
                            f_GetData(PageIndex);
                        } else {
                            $kk.popup("操作失败", "danger", 1000);
                        }
                    });
                }, null);
        }

        function f_ExportExcel() {
            var newUrlParStr = f_UrlParStr();
            $kk.api.get("/ProductsExchange/Export" + newUrlParStr, function (res) {
                //window.location.href = window.location.host + res;
                //window.open(window.location.host + res)
                //$("#DownLoad").attr("href", window.location.host + res)
                $("#DownLoad").attr("href", res)
                $("#DownLoad").show();
            });
        }

        function ChangeRefresh() {
            $("#F_ExchangeType").change(function () {
                f_GetData(1);
            });
            $("#F_CateogryKid").change(function () {
                f_GetData(1);
            });
            $("#F_CityKid").change(function () {
                f_GetData(1);
            });
            $("#F_Status").change(function () {
                f_GetData(1);
            });
        }

    </script>
</body>
</html>
